package com.sunday.commlibrary;

import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.view.SimpleDraweeView;
import com.squareup.picasso.Picasso;

/**
 * Created by liu on 2017/3/9.
 */

public class FrescoActivity extends AppCompatActivity {

    private SimpleDraweeView simpleDraweeView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Fresco.initialize(this);
        setContentView(R.layout.activity_fresco);

        simpleDraweeView = (SimpleDraweeView) findViewById(R.id.image);

        //创建将要下载的图片的URI
        final Uri imageUri = Uri.parse("http://img07.mifile.cn/v1/MI_55950AFBBEDCB/T1madQBXZT1RXrhCrK.jpg");
        //开始下载
        simpleDraweeView.setImageURI(imageUri);


//        //创建DraweeController
//        DraweeController controller = Fresco.newDraweeControllerBuilder()
//                //加载的图片URI地址
//                .setUri(imageUri)
//                //设置点击重试是否开启
//                .setTapToRetryEnabled(true)
//                //设置旧的Controller
//                .setOldController(simpleDraweeView.getController())
//                //构建
//                .build();
//
//        //设置DraweeController
//        simpleDraweeView.setController(controller);


        simpleDraweeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                simpleDraweeView.setImageResource(R.mipmap.icon_failure);
                Picasso.with(FrescoActivity.this).load(imageUri).into(simpleDraweeView);
            }
        });
    }
}
